package com.ruoyi.project.wf.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.wf.mapper.WfProcessActMapper;
import com.ruoyi.project.wf.domain.WfProcessAct;
import com.ruoyi.project.wf.service.IWfProcessActService;
import com.ruoyi.common.utils.text.Convert;

import javax.annotation.Resource;

/**
 * 流程节点信息Service业务层处理
 *
 * @author XQ.XU
 * @date 2020-03-20
 */
@Service
public class WfProcessActServiceImpl extends ServiceImpl<WfProcessActMapper, WfProcessAct> implements IWfProcessActService
{
    @Resource
    private WfProcessActMapper wfProcessActMapper;

    /**
     * 查询流程节点信息
     *
     * @param id 流程节点信息ID
     * @return 流程节点信息
     */
    @Override
    public WfProcessAct selectWfProcessActById(String id)
    {
        return wfProcessActMapper.selectWfProcessActById(id);
    }

    /**
     * 查询流程节点信息列表
     *
     * @param wfProcessAct 流程节点信息
     * @return 流程节点信息
     */
    @Override
    public List<WfProcessAct> selectWfProcessActList(WfProcessAct wfProcessAct)
    {
        return wfProcessActMapper.selectWfProcessActList(wfProcessAct);
    }

    /**
     * 新增流程节点信息
     *
     * @param wfProcessAct 流程节点信息
     * @return 结果
     */
    @Override
    public int insertWfProcessAct(WfProcessAct wfProcessAct)
    {
        wfProcessAct.setCreateTime(DateUtils.getNowDate());
        return wfProcessActMapper.insertWfProcessAct(wfProcessAct);
    }

    /**
     * 修改流程节点信息
     *
     * @param wfProcessAct 流程节点信息
     * @return 结果
     */
    @Override
    public int updateWfProcessAct(WfProcessAct wfProcessAct)
    {
        wfProcessAct.setUpdateTime(DateUtils.getNowDate());
        return wfProcessActMapper.updateWfProcessAct(wfProcessAct);
    }

    /**
     * 删除流程节点信息对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWfProcessActByIds(String ids)
    {
        return wfProcessActMapper.deleteWfProcessActByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除流程节点信息信息
     *
     * @param id 流程节点信息ID
     * @return 结果
     */
    @Override
    public int deleteWfProcessActById(String id)
    {
        return wfProcessActMapper.deleteWfProcessActById(id);
    }

    @Override
    public WfProcessAct selectStartNode(String procDefId, int ActType) {
        WfProcessAct wfProcessAct=new WfProcessAct();
        wfProcessAct.setActType(ActType);
        wfProcessAct.setProcDefId(procDefId);
        List<WfProcessAct>wfProcessActs= wfProcessActMapper.selectWfProcessActList(wfProcessAct);
        return (wfProcessActs!=null& wfProcessActs.size()>0)?wfProcessActs.get(0):null;
    }
}
